<%--
  Created by IntelliJ IDEA.
  User: 陈帅玺
  Date: 2019-01-04
  Time: 10:07
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<c:set var="path" value="${pageContext.request.contextPath}"></c:set>
<html>
<head>
    <title>创建服务</title>
    <link rel="stylesheet" href="${path}/layui/css/layui.css">
    <script src="${path}/js/jquery.min.js"></script>
    <script src="${path}/js/jquery-3.3.1.js"></script>
    <script src="${path}/layui/layui.js"></script>
    <script src="${path}/js/config.js"></script>
    <link rel="shortcut icon" href="${path}/assets/ico/minus.png">
    <style>
        .box-pad {
            padding: 1%
        }
        .layui-form-item{
            margin-bottom: 35px;
        }
    </style>
</head>
<body>
<div class="box-pad">
    <h1>服务创建</h1>
    <hr>
    <form class="layui-form" id="serviceForm" method="post" lay-filter="serviceForm">
        <%--//创建人的id--%>
        <input type="hidden" name="founderId" value="${sessionScope.login_user.id}" id="founderId">
        <%-- 状态--%>
        <input type="hidden" name="state" value="1">
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">客户</label>
                <div class="layui-input-inline">
                    <input type="text" id="kehu" name="clientele" autofocus autocomplete="off" class="layui-input" placeholder="请输入客户名称">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">服务类型：</label>
                <div class="layui-inline">
                    <select id="serviceType" name="typeid">
                        <option value="-1">请选择</option>
                        <c:forEach items="${crmDictionaries}" var="service">
                            <option value="${service.id}">${service.name}</option>
                        </c:forEach>
                    </select>
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">概要</label>
            <div class="layui-input-block">
                <input type="text" name="outline" id="gaiyao" autocomplete="off" class="layui-input" placeholder="请输入概要">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">服务请求</label>
            <div class="layui-input-block">
                <textarea placeholder="请输入请求" id="qingqiu" autocomplete="off" name="request" class="layui-textarea"></textarea>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">创建人</label>
                <div class="layui-input-inline">
                    <input type="text" class="layui-input" value="${sessionScope.login_user.username}" id="founderName" readonly>
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">创建时间</label>
                <div class="layui-input-inline">
                    <input type="text" name="creatorTime" class="layui-input" value="" id="creationTime" readonly>
                </div>
            </div>
        </div>
        <div class="layui-form-item" style="text-align: center">
            <button type="button"  class="layui-btn layui-btn-lg" onclick="sumb();">提交</button>
        </div>
    </form>
    <script>
        function getNow(s) {
            return s < 10 ? '0' + s: s;
        }
        function dates() {
            var now = new Date();
            //格式化日，如果小于9，前面补0
            var day = ("0" + now.getDate()).slice(-2);
            //格式化月，如果小于9，前面补0
            var month = ("0" + (now.getMonth() + 1)).slice(-2);
            var h = now.getHours();
            var minute = now.getMinutes();
            var s = now.getSeconds();
            //拼装完整日期格式
            var today = now.getFullYear()+"-"+(month)+"-"+(day)+" "+getNow(h)+":"+getNow(minute)+":"+getNow(s);
            return today;
        }
        layui.use('form', function () {
            var form = layui.form;
            //  获取时间
            $("#creationTime").val(dates());

        });
        function sumb(){
            var kehus=$("#kehu").val();
            var gaiyaos=$("#gaiyao").val();
            var qingqius =$("#qingqiu").val();
            if(kehus==null || kehus=="" && gaiyaos==null|| gaiyaos=="" && qingqius==null|| qingqius==""){
                layer.msg("仔细填写...",{icon:5,time:1200,offset:'260px',anim:6},function () {});
                return false;
            }
            var serviceForm=$("#serviceForm").serialize();
            console.log(serviceForm);
            $.post("${path}/Service/addService",serviceForm,function () {
                 layui.layer.msg("提交成功...",{ time:1200,offset: '300px' },function () {
                     document.getElementById("serviceForm").reset();        //清空form表单内容
                     $("#creationTime").val(dates());
                 })
            })
        }
        //  layui渲染

    </script>
</div>
</body>
</html>
